package com.asa.jihe.E;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.asa.jihe.utils.Euclid;
import com.asa.jihe.utils.Line;
import com.asa.jihe.utils.Point;





/**
 * vorinoi图
 * @author asa
 *
 */
public class Vorinoi {
	
	//文档和教程感觉不适合我，我是真的皮
	//我就按照自己所想的方法来实现吧
	
	public static void main(String[] args) {
		
	}
	
	/**
	 * 这个是通过不断补充三角形来做的
	 * 你看代码风格就知道，这个不是我实现的原理，这个太难写了
	 * @param points
	 * @return
	 */
	public static List<Line> func1(List<Point> points) {
		
		List<Line> result = new ArrayList<Line>();
		
		int initialSize = 10000;  
		Triangle<Vpoint> initialSuperTriangle = new Triangle<Vpoint>(new Vpoint(-initialSize, -initialSize),
                new Vpoint( initialSize, -initialSize),
                new Vpoint(           0,  initialSize));
		Delaunay delaunay = new Delaunay(initialSuperTriangle);
		
		for (int i = 0; i < points.size(); i++) {
			
			Vpoint point = new Vpoint(points.get(i).x,points.get(i).y);
	        delaunay.PointInsert(point);

		}
		
		
		
		
		for (Triangle<Vpoint> triangle: delaunay)
	        for (Triangle<Vpoint> anotherTriangle: delaunay.getNeighbors(triangle)) {
	            Vpoint t = Vpoint.circlecenterOfTri(triangle.toArray(new Vpoint[0]));
	            Vpoint a = Vpoint.circlecenterOfTri(anotherTriangle.toArray(new Vpoint[0]));
	            

	            
	            Point spoint = new Point();
	            Point epoint = new Point();

	            spoint.x = t.getXY(0);
	            spoint.y = t.getXY(1);
	            epoint.x = a.getXY(0);
	            epoint.y = a.getXY(1);
	            
	            Line line = new Line();
	            
	            line.spoint = spoint;
	            line.epoint = epoint;

	            result.add(line);
	        }
		
		
		
		List<Line> result2 = new ArrayList<Line>();

		a:for (int i = 0; i < result.size(); i++) {
			
			for (int j = 0; j < result2.size(); j++) {
				
				Line line1 = result2.get(j);
				Line line2 = result.get(i);
				boolean issameline = Euclid.issameline(line1, line2);
				
				if (issameline) {
					System.out.println("continue");
					continue a;
				}
				
			}
			result2.add(result.get(i));
			
		}
		
		
		
		
		
		return result2;
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	

}
